$(document).ready(function(){
	$("#countrynname").blur(function(){
		$.post("../whitherJson!returnCountryCode.action",{"name":this.value},function(data){
			$("#countryccode").attr("value",data.countryCode);
			var pro = document.getElementById("proNum");
			if(data.countryCode == "CN"){
				pro.options.length = 1;
				document.getElementById("cityNum").options.length = 1;
				document.getElementById("areNum").options.length = 1;
				$(data.provinces).each(function(){
					pro.options.add(new Option(this.clinentProvinceName,this.clinentProvinceNumber));
				})
			}else{
				pro.options.length = 1;
				document.getElementById("cityNum").options.length = 1;
				document.getElementById("areNum").options.length = 1;
			}
		});
	});
	$("#proNum").change(function(){
		var cit = document.getElementById("cityNum");
//		var arry = new Array();
		if(this.value != -1){
			cit.options.length = 1;
			$.post("../whitherJson!findCitys.action",{"proNumber":this.value},function(data){
				$(data.citys).each(function(){
					cit.options.add(new Option(this.clinentCityName,this.clinentCityNumber));
//					arry.push([this.clinentCityNumber,this.clinentCityName]);
				});
//				return arry;
			});
		}else{
			cit.options.length = 1;
			document.getElementById("areNum").options.length = 1;
		}

	});

	
	$("#cityNum").change(function(){
		var are = document.getElementById("areNum");
		if(this.value != -1){
			are.options.length = 1;
			$.post("../whitherJson!findAreas.action",{"cityNumber":this.value},function(data){
				$(data.areas).each(function(){
					are.options.add(new Option(this.clinentAreaName,this.clinentAreaNumber + "," + this.clinentAreaCode));
				});
			});
		}else{
			are.options.length = 1;
		}
	});
	
	$("#areNum").change(function(){
		var areaCode = document.getElementById("areaCode");
		if(this.value != -1){0
			areaCode.value = "";
			var a = this.value.split(",");
			areaCode.value = a[1];
		}
	});
});